package life.system.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import life.system.product.entity.CityEntity;
import life.system.product.vo.CityResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import life.system.product.service.CityService;
import life.system.common.utils.PageUtils;
import life.system.common.utils.R;


@RestController
@RequestMapping("product/city")
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {

        PageUtils page = cityService.queryPage(params);
        System.out.println(page);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        CityEntity city = cityService.getById(id);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CityEntity city) {
        cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CityEntity city) {
        cityService.updateById(city);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        cityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 获取全部数据
     */
    @RequestMapping("/getAll")
    public R getAll() {
        List<CityEntity> list = cityService.list();
        return R.ok().put("data", list);
    }


    /**
     * 获取全部数据
     */
    @RequestMapping("/lists")
    public R lists() {
        List<CityResult> list = cityService.lists();
        return R.ok().put("data", list);
    }
}
